package Controller.Member;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import Bean.JoinBean;
import Bean.MemberBean;
import Bean.MusicBean;
import Dao.MemberDao;

public class MemberBuylist implements Controller{
	private MemberDao member;
	
	public void setMember(MemberDao member) {
		this.member = member;
	}
	@Override
	public ModelAndView handleRequest(HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		String m_id = req.getParameter("m_id");
		System.out.println("buylist Controller 로 넘어온 값 : "+m_id);
		MemberBean bean = new MemberBean();
		
		bean.setM_id(m_id);
		List<JoinBean> buylist = member.mBuylist(m_id);
		
		for (JoinBean joinBean : buylist) {
			bean = joinBean.getMemberBean();
			MusicBean music = joinBean.getMusicBean();
			if(joinBean.getMusicBean().getMs_featuring().equals("없음")){
				music.setMs_featuring("");
				joinBean.setMusicBean(music);
			}else{
				music.setMs_featuring("(feat."+music.getMs_featuring()+")");
				joinBean.setMusicBean(music);
			}
			System.out.println(joinBean.getMusicBean().getMs_album());
			System.out.println(joinBean.getMusicBean().getMs_title());
			System.out.println(joinBean.getMusicBean().getMs_featuring());
			System.out.println(joinBean.getSingerBean().getS_singer());
			System.out.println(joinBean.getMusicBean().getMs_genre());
		}
		ModelAndView mav = new ModelAndView();
		mav.setViewName("buylist");
		mav.addObject("buylistall",buylist);
		return mav;
	}
}